package com.mogu.biguser.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mogu.biguser.common.util.DateUtil;
import com.mogu.biguser.domain.base_sys.SysArea;
import com.mogu.biguser.domain.base_sys.SysDept;
import com.mogu.biguser.service.BigUserService;
import com.mogu.biguser.service.dto.ParamValue;
import com.mogu.biguser.service.dto.biguser.BigUser;
import com.mogu.biguser.web.api.model.BaseResponse;
import org.apache.ibatis.annotations.Param;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/api/biguser")
public class BigUserController {

    private static final Logger logger = LoggerFactory.getLogger(BigUserController.class);
    @Resource
    public BigUserService bigUserService;

    /**
     * 档案管理
     * @param user
     * @return
     */
    @RequestMapping(value = "/record/list", method = RequestMethod.POST)
    public BaseResponse<PageInfo> index(@RequestParam(value = "pageSize",defaultValue = "10")Integer pageSize,@RequestParam(value = "pageNum",defaultValue = "1")Integer pageNum, BigUser user)
    {
        List<BigUser> list =null;
        PageInfo pageInfo = null;
        try {
            PageHelper.startPage(pageNum,pageSize);
            list =      bigUserService.findListBigUser(user);
            pageInfo = new PageInfo<BigUser>(list);
        }catch (Exception e){
            e.printStackTrace();
        }
        //

        return  new BaseResponse<PageInfo>(true, "档案管理", pageInfo);
    }


    /**
     *  新增档案
     * @param user
     * @return
     */
    @RequestMapping(value = "/add/biguser", method = RequestMethod.POST)
    public BaseResponse<Object> addBigUser(@RequestBody BigUser user)
    { int i =0;
        try {
            String productionTime = user.getTime();
          //  Date parse = DateUtil.parse(productionTime, "yyyy-MM-dd");
            user.setProductionTime(productionTime);
            i =      bigUserService.addBigUser(user);
        }catch (Exception e){
            e.printStackTrace();
        }

        return  new BaseResponse<Object>(true, "新增档案", i);
    }

    /**
     *  查询档案
     * @param user
     * @return
     */
    @RequestMapping(value = "/look/biguser", method = RequestMethod.POST)
    public BaseResponse<Object> lookBigUser(BigUser user)
    {    BigUser bigUser = null;
        try {
              /*  bigUserService
*/
        }catch (Exception e){
            e.printStackTrace();
        }

        return  new BaseResponse<Object>(true, "查询档案", bigUser);
    }

    /**
     *  删除档案
     * @param user
     * @return
     */
    @RequestMapping(value = "/remove/biguser", method = RequestMethod.POST)
    public BaseResponse<Object> removeBigUser(String strs)
    {

        int i =0;
        try {

            i =      bigUserService.removeBigUser(strs);
        }catch (Exception e){
            e.printStackTrace();
        }

        return  new BaseResponse<Object>(true, "删除档案", i);
    }

    /**
     *  用户编号判断
     * @param user
     * @return
     */
    @RequestMapping(value = "/isUserNum", method = RequestMethod.POST)
    public BaseResponse<Object> isUserNum(@RequestBody BigUser user)
    { String mess ="0";
        try {

            mess =      bigUserService.isUserNum(user);
        }catch (Exception e){
            e.printStackTrace();
        }

        return  new BaseResponse<Object>(true, "用户编号判断", mess);
    }
















    /**
     *  月均用水   --- 分析统计使用
     */
    @RequestMapping(value = "/avgmonth", method = RequestMethod.POST)
    public BaseResponse<List<ParamValue>> avgMonth() {
        List<ParamValue>  s=null;
        try{
            s = bigUserService.findListAvgMonth();

        }catch (Exception e){
            logger.error(e.getMessage(), e);
            e.printStackTrace();
        }

        return new BaseResponse<List<ParamValue>>(true, "月均用水", s );
    }








    /**
     * 用户类型
     */
    @RequestMapping(value = "/types", method = RequestMethod.POST)
    public BaseResponse<List<ParamValue>> types() {
        List<ParamValue>  s=null;
        try{
            s = bigUserService.findListTypes();

        }catch (Exception e){
            logger.error(e.getMessage(), e);
            e.printStackTrace();
        }

        return new BaseResponse<List<ParamValue>>(true, "用户类型", s );
    }

    /**
     * 行业
     */
    @RequestMapping(value = "/industry", method = RequestMethod.POST)
    public BaseResponse<List<ParamValue>> industry() {
        List<ParamValue>  s=null;
        try{
            s = bigUserService.findListIndustry();

        }catch (Exception e){
            logger.error(e.getMessage(), e);
            e.printStackTrace();
        }

        return new BaseResponse<List<ParamValue>>(true, "用户类型", s );
    }

    /**
     *  节水型企业
     */
    @RequestMapping(value = "/enterprise", method = RequestMethod.POST)
    public BaseResponse<List<ParamValue>> enterprise() {
        List<ParamValue>  s=null;
        try{
            s = bigUserService.findListEnterprise();

        }catch (Exception e){
            logger.error(e.getMessage(), e);
            e.printStackTrace();
        }

        return new BaseResponse<List<ParamValue>>(true, "行业", s );
    }

    /**
     *  用水类型
     */
    @RequestMapping(value = "/water/type", method = RequestMethod.POST)
    public BaseResponse<List<ParamValue>> waterType() {
        List<ParamValue>  s=null;
        try{
            s = bigUserService.findListWaterType();

        }catch (Exception e){
            logger.error(e.getMessage(), e);
            e.printStackTrace();
        }

        return new BaseResponse<List<ParamValue>>(true, "行业", s );
    }


    /**
     * 选择片区
     *
     * @return
     */
    @RequestMapping(value = "/selArea", method = RequestMethod.POST)
    public BaseResponse<List<SysArea>> selOrderArea() {
        List<SysArea> orderDepts = null;
        try {
            orderDepts = bigUserService.findListArea();
        } catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getMessage(), e);
        }
        return new BaseResponse<List<SysArea>>(true, "查询片区", orderDepts);
    }

    /**
     * 选择部门
     *
     * @return
     */
    @RequestMapping(value = "/selDept", method = RequestMethod.POST)
    public BaseResponse<List<SysDept>> selDept(String areaId) {
        List<SysDept> orderDepts = null;
        try {
            orderDepts = bigUserService.findListDept(areaId);
        } catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getMessage(), e);
        }
        return new BaseResponse<List<SysDept>>(true, "选择部门", orderDepts);
    }








}
